import java.io.PrintStream;
import java.util.concurrent.Semaphore;

import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

public class paircovTest extends Thread/* extends TestCase */{

	static final int timeOut = 1000000;
	
	static paircovInterf p;
	String[][] tableau;
	private  String[][] s;

	@Before
	public  void setUp() {
		p = new paircov();

		// fabrication de la variable s.
		int[] tSize = new int[] { 1, 5, 1, 2, 7 };
		int t = tSize.length;

		s = new String[t][];
		for (int f = 0; f < t; f++) {
			int tt = t;
			tt = tSize[f];
			tt++;
			s[f] = new String[tt];

			for (int g = 0; g < tt; g++) {
				String ajout = "";
				if (g != 2) {
					ajout = "" + g;
				}
				s[f][g] = "" + ajout;
			}
		}

	}
	
	

	// @Test(timeout = timeOut)
	public void testInconclusive() {
		test(new String[][] { new String[] { "a", "a" }, new String[] { "a" },
				new String[] { "a" } });
	}

	// @Test(timeout = timeOut)
	public void testSequence_0() {
		try {
			tableau = new String[3][];
			String[] x1 = { "Paris", "Lyon", "Grenoble" };
			String[] x2 = { "Lille", "Annecy", "Lyon" };
			String[] x3 = { "1/1/04", "4/4/04", "1/8/04" };
			// String[] x4 = { "6", "17", "23" };
			tableau[0] = x1;
			tableau[1] = x2;
			tableau[2] = x3;
			// tableau[3] = x4;
			p.generate(tableau);
		} catch (org.jmlspecs.jmlrac.runtime.JMLEntryPreconditionError e$) {
			System.out.println("\n INCONCLUSIVE "
					+ (new Exception().getStackTrace()[0].getMethodName())
					+ "\n\t " + e$.getMessage());
		} catch (org.jmlspecs.jmlrac.runtime.JMLAssertionError e$) {
			// test failure
			int l$ = org.jmlspecs.jmlrac.runtime.JMLChecker.getLevel();
			org.jmlspecs.jmlrac.runtime.JMLChecker
					.setLevel(org.jmlspecs.jmlrac.runtime.JMLOption.NONE);
			try {
				junit.framework.Assert.fail("\n\t" + e$.getMessage());
			} finally {
				org.jmlspecs.jmlrac.runtime.JMLChecker.setLevel(l$);
			}
		}
	}


	@Test(timeout = timeOut)
	public void testVide() {
		test(new String[][] {});
	}


	@Test(timeout = timeOut)
	public void testChaineVide() {
		test(new String[][] { { "" } });
	}


	@Test(timeout = timeOut)
	public void testTailleCroissante() {
		test(new String[][] { new String[] { "a" }, new String[] { "b", "c" } });
	}


	@Test(timeout = timeOut)
	public void testTailleDecroissante() {
		test(new String[][] { new String[] { "a", "b" }, new String[] { "d" } });
	}


	@Test(timeout = timeOut)
	public void testPlusieursParam() {
		int t = 101;
		String[][] s = new String[t][];
		String s2 = "";
		for (int f = 0; f < t; f++) {
			s[f] = new String[] { s2 };
		}
		test(s);
	}


	@Test(timeout = timeOut)
	public void testGrosParam() {
		int t = 101;
		String[][] s = new String[1][t];
		for (int f = 0; f < t; f++) {

			s[0][f] = "" + f;
		}
		test(s);
	}


	@Test
	public void testTaillesDiff() {

		test(s);
	}

	@Test
	public void testTaillesDiff2fois() {

		test(s);
		test(s);
	}


	//@Test
	public void testTaillesDiffMultiThread() {

		
		for (int i = 0; i < 10; i++) {
			paircovTest thread = new paircovTest();
			thread.start();
		}
		
		try {
		// on attend un peu les autres threads.
		Thread.currentThread().sleep(1000);
		} catch (java.lang.InterruptedException e){}
	}

	@Override
	public void run() {
		test(s);
	}

	public void test(String[][] params) {

		try {
			PrintStream so = System.out;
			try {
				System.setOut(null);
				p.generate(params);
			} finally {
				System.setOut(so);
			}

		} catch (org.jmlspecs.jmlrac.runtime.JMLEntryPreconditionError e$) {
			Assert.fail("\n INCONCLUSIVE "
					+ (new Exception().getStackTrace()[0].getMethodName())
					+ "\n\t " + e$.getMessage());
		} catch (org.jmlspecs.jmlrac.runtime.JMLAssertionError e$) {
			// test failure
			int l$ = org.jmlspecs.jmlrac.runtime.JMLChecker.getLevel();
			org.jmlspecs.jmlrac.runtime.JMLChecker
					.setLevel(org.jmlspecs.jmlrac.runtime.JMLOption.NONE);
			try {
				Assert.fail("\n\t" + e$.getMessage());
				// Assert.fail();
			} finally {
				org.jmlspecs.jmlrac.runtime.JMLChecker.setLevel(l$);
			}
		} catch (Throwable t) {
			Assert.fail("\n\t" + t.getMessage());
		}
	}

}
